package com.sun.hunk.hibernate.dao;

import com.sun.hunk.hibernate.BaseHibernateDAO;
import com.sun.hunk.hibernate.domain.Category;
import com.sun.hunk.hibernate.domain.impl.CategoryImpl;
import com.sun.hunk.util.CommonUtil;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author sunil
 */
public class CategoryDAO extends BaseHibernateDAO<CategoryImpl> {

    public CategoryDAO() {
        super(CategoryImpl.class);
    }

    public boolean isCategoryExist(String desc) {
        List list = new CategoryDAO().findByProperty("description", desc);
        if (CommonUtil.isNotEmpty(list)) {
            return true;
        } else {
            return false;
        }
    }

    public List<Category> findAllParent() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("parent", null);
        return new CategoryDAO().find(map);
    }

    public List<CategoryImpl> findAll() {
        return new CategoryDAO().findAll();
    }

    public List<Category> findSubcategories(Integer id) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("parent", id);
        return find(map);
    }
}
